home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 657 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.4 KB

  1. From: "Nathan Myers, http://www.cantrip.org/" <ncm@cantrip.org>
  2. Message-ID: <313E19BB.5AE2E407@cantrip.org>
  3. X-Original-Date: Wed, 06 Mar 1996 15:03:23 -0800
  4. Path: in1.uu.net!bounce-back
  5. Date: 08 Mar 96 02:04:53 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Re: no operator bool()?
  9. Organization: The Cantrip Cooperative
  10. References: <313ddfd9.16044605@sqarc.sq.com>
  11. X-Mailer: Mozilla 2.0 (X11; I; Linux 1.2.13 i386)
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBFAgUBMT+V3+EDnX0m9pzZAQGbxQF8CqwUYgMZBVKN/RX8owym5QP+1KOYa6+k
  14.     EPFWc4BEE4Z1BSN/Jyg6EKfyOCr5jg/E
  15.     =z+FX
  16.  
  17. Steve Willer wrote:
  18. > ... the (April '95) draft standard auto_ptr doesn't have an operator
  19. > bool() function in it, making it inconvenient to write "if (ptr)" type
  20. > constructs. Is there some sort of reason for that? I know that implicit type
  21. > conversion is generally a bad thing, but I can't see how this one would be
  22. > particularly dangerous (also, can the new explicit keyword be used on the
  23. > return type?).
  24.  
  25. Automatic conversion only to bool would not, as Steve suggests, be
  26. likely to cause problems.  However, once converted to bool, it would
  27. then convert freely to int, char, or double.  
  28.  
  29. > the latest iostream standard has an operator bool() and an operator!() 
  30. > defined. So why not be consistent?
  31.  
  32. This problem is serious enough that the Core working group has resolved
  33. to consider restricting conversion sequences involving bool. 
  34.  
  35. If the Core WG doesn't resolve the problem, the Library WG will replace
  36. iostream's operator bool() with operator void*().  (This alternative is 
  37. less attractive in the case of auto_ptr<>, where it would cause confusion.)
  38.  
  39. Automatic conversions can be a problem in general, but the problems 
  40. with automatic conversions to a numeric type are ridiculous.  
  41. Compatibility with C has its downside. 
  42.  
  43. As a side note...  The problem with automatic conversions is not
  44. only that the conversion may be called unexpectedly; the 
  45. possibility of the conversion affects overloading, so it may 
  46. force you to add "unnecessary" casts to guide the compiler to 
  47. the correct choice of function to call.
  48.  
  49. Nathan Myers
  50. ncm@cantrip.org   http://www.cantrip.org/
  51. ---
  52. [ To submit articles: try just posting with your news-reader.
  53.                       If that fails, use mailto:std-c++@ncar.ucar.edu
  54.   FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  55.   Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  56.   Comments? mailto:std-c++-request@ncar.ucar.edu.
  57. ]
  58.